package org.se.scut.pinserver.main;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.charset.Charset;
import java.util.Date;


import org.apache.mina.core.service.IoAcceptor;
import org.apache.mina.core.session.IdleStatus;
import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.filter.codec.textline.LineDelimiter;
import org.apache.mina.filter.codec.textline.TextLineCodecFactory;
import org.apache.mina.transport.socket.nio.NioSocketAcceptor;
import org.se.scut.hibernate.dao.PictureTypeDAO;
import org.se.scut.hibernate.dao.model.PictureType;
import org.se.scut.hibernate.dao.service.PictureServiceImp;
import org.se.scut.hibernate.dao.service.PictureTypeImp;
import org.se.scut.hibernate.dao.service.iface.IPictureTypeService;
import org.se.scut.pinterest.mina.codec.filte.PictureUploadCodecFactory;
import org.se.scut.pinterest.mina.codec.msg.PictureUploadMessage;
import org.se.scut.pinterest.mina.handler.ServerIOHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ServerStarter {

	private static final Logger LOGGER = LoggerFactory.getLogger(ServerStarter.class);
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		createServer();
		
	}

	private static void createServer()
	{
		IoAcceptor acceptor = new NioSocketAcceptor();
		acceptor.getSessionConfig().setReadBufferSize(2028);
		acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 10);
		acceptor.getFilterChain().addLast("textLine",
				new ProtocolCodecFilter(new PictureUploadCodecFactory(true)));
		acceptor.setHandler(new ServerIOHandler());
		try {
			acceptor.bind(new InetSocketAddress(9123));
		} catch (IOException e) {
			LOGGER.error(e.getMessage());
		}
	}
	
	
}
